package com.hxkcloud.nurse.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.YjhApplication;
import com.hxkcloud.nurse.activitys.MessageMainActivity;
import com.hxkcloud.nurse.activitys.PatientBetterPlanActivity;
import com.hxkcloud.nurse.activitys.QuestionListActivity;
import com.hxkcloud.nurse.activitys.ScaleQuestionActivity;

/**
 * Created by william_sun on 2016-07-06.
 * Description:助手模块
 */
public class AssistantFragment extends BaseFragment implements View.OnClickListener {

    private View view;
    private LinearLayout ll_title;
    private ImageView iv_search;
    private TextView tv_title;
    private ImageView iv_message;
    private ImageView iv_msgpoint;

    private LinearLayout ll_empty;
    private RelativeLayout ll_info;

    //    private ImageView performIV;
//    private ImageView remindIV;
    private ImageView recoveryIV;
    private ImageView scaleIV;
    private ImageView questionIV;
    private TextView msg_number;
    private boolean showIcon;

    public AssistantFragment(){
        super();
    }

    public void showPoint(boolean show) {
        showIcon = show;
        if (iv_msgpoint != null)
            if (show) {
                iv_msgpoint.setVisibility(View.VISIBLE);
            } else {
                iv_msgpoint.setVisibility(View.INVISIBLE);
            }
        YjhApplication.getInstance().showMsg(msg_number);
    }

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {

        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_assistant_show, container, false);
        initView();
        initData();
        initListener();
        return view;
    }

    public void onResume() {
        super.onResume();
        if (TextUtils.isEmpty(loginInfo.getDepartmentId())) {
            ll_empty.setVisibility(View.VISIBLE);
            ll_info.setVisibility(View.GONE);
        } else {
            initData();
            ll_empty.setVisibility(View.GONE);
            ll_info.setVisibility(View.VISIBLE);
        }


        YjhApplication.getInstance().showMsg(msg_number);
    }

    @Override
    protected void initView() {
        ll_title = (LinearLayout) view.findViewById(R.id.ll_title);
        iv_search = (ImageView) view.findViewById(R.id.iv_title_back);
        tv_title = (TextView) view.findViewById(R.id.tv_title_title);
        iv_message = (ImageView) view.findViewById(R.id.iv_title_func);
        iv_msgpoint = (ImageView) view.findViewById(R.id.iv_title_point);
        msg_number = (TextView) view.findViewById(R.id.msg_number);


        setTitlePadding(ll_title);
        iv_search.setVisibility(View.INVISIBLE);
        tv_title.setText(getResources().getText(R.string.assistant_text_title));
        iv_message.setVisibility(View.VISIBLE);
        iv_message.setImageResource(R.mipmap.nav_message);
        iv_search.setOnClickListener(this);
        iv_message.setOnClickListener(this);

        ll_empty = (LinearLayout) view.findViewById(R.id.ll_department_empty);
        ll_info = (RelativeLayout) view.findViewById(R.id.ll_assistant_info);

//        performIV = (ImageView) view.findViewById(R.id.assistant_iv_perform);
//        remindIV = (ImageView) view.findViewById(R.id.assistant_iv_remind);
        recoveryIV = (ImageView) view.findViewById(R.id.assistant_iv_recovery);
        scaleIV = (ImageView) view.findViewById(R.id.assistant_iv_scale);
        questionIV = (ImageView) view.findViewById(R.id.assistant_iv_question);

        if (showIcon) {
            iv_msgpoint.setVisibility(View.VISIBLE);
        } else {
            iv_msgpoint.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    protected void initListener() {
        iv_message.setOnClickListener(this);
//        performIV.setOnClickListener(this);
//        remindIV.setOnClickListener(this);
        recoveryIV.setOnClickListener(this);
        scaleIV.setOnClickListener(this);
        questionIV.setOnClickListener(this);

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_title_func://消息
                if (!TextUtils.isEmpty(loginInfo.getDepartmentId())) {
                    Intent iM = new Intent(mContext, MessageMainActivity.class);
                    startActivity(iM);
                } else {
                    toastMsg(R.string.pleasefirstjoindepartment);
                }
                break;
//            case R.id.assistant_iv_perform://执行单
//                Intent performIntent = new Intent(getActivity(), PerformListActivity.class);
//                performIntent.putExtra("type", 0);
//                startActivity(performIntent);
//                break;
//            case R.id.assistant_iv_remind://提醒单
//                Intent remindIntent = new Intent(getActivity(), PerformListActivity.class);
//                remindIntent.putExtra("type", 1);
//                startActivity(remindIntent);
//                break;
            case R.id.assistant_iv_recovery:
                Intent recoveryIntent = new Intent(getActivity(), PatientBetterPlanActivity.class);
                startActivity(recoveryIntent);
                break;
            case R.id.assistant_iv_scale://量表
                Intent scaleIntent = new Intent(getActivity(), ScaleQuestionActivity.class);
                scaleIntent.putExtra("isFromAssistant", "true");
                startActivity(scaleIntent);
                break;
            case R.id.assistant_iv_question://调查问卷
                Intent questionIntent = new Intent(getActivity(), QuestionListActivity.class);
                questionIntent.putExtra("isFromAssistant", "true");
                startActivity(questionIntent);
                break;


        }

    }
    public static AssistantFragment newInstance(){

        return new AssistantFragment();
    }
}
